from celery import Celery


# 注意注意：
# 一、加载django配置环境
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BookStore.settings')
# 二、加载celery配置环境
from celery import Celery
# broker
broker = 'redis://127.0.0.1:6379/0'
# backend
backend = 'redis://127.0.0.1:6379/1'
# worker
app = Celery(BROKER_CONNECTION_RETRY_ON_STARTUP=True,broker=broker, backend=backend, include=['celery_task.task'])
# 定时任务需要写在这里
# 时区
app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC
app.conf.enable_utc = False
### celery的配置信息---结束###
#### 定时任务
from datetime import timedelta
from celery.schedules import crontab
app.conf.beat_schedule = {
    '月度报告': {
        'task': 'celery_task.task.create_report',  # 哪个任务
        'schedule': timedelta(seconds=6),
        # 'schedule': crontab(minute=42, hour=8, day_of_month=11, month_of_year=4),
        'args': (),
    },
}
